package com.sjdang.springcloud.learning.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.sjdang.springcloud.learning.service.HelloService;

@Service
public class HelloServiceImpl implements HelloService {
	
	@Resource
	private RestTemplate restTemplate;

	@Override
	@HystrixCommand(fallbackMethod="sayError")
	public String sayHello(String name) {
		return restTemplate.getForObject("http://EUREKA-CLIENT/learning/api/hello?name="+name, String.class);
	}
	
	public String sayError(String name) {
		return "Hi, " + name + ", I am so sorry for error.";
	}

}
